<template>
  <div>
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
      <template #tableTitle>
      </template>
      <template #action="{ record }">
        <TableAction :actions="getActions(record)" />
      </template>
    </BasicTable>
    <TenantUserModal @register="registerTenUserModal" />
  </div>
</template>
<script lang="ts" name="tenant-my-tenant-list" setup>
import { onMounted, ref, unref } from 'vue';
import { BasicTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import { getTenantList } from '../tenant.api';
import { columns, searchFormSchema } from '../tenant.data';
import { useMessage } from '/@/hooks/web/useMessage';
import { useListPage } from '/@/hooks/system/useListPage';
import TenantUserModal from '../components/TenantUserList.vue';
import { getTenantId } from '/@/common/util/auth';
import { useUserStore } from '/@/store/modules/user';
import { tenantSaasMessage } from "/@/utils/common/compUtils";

const { createMessage } = useMessage();
const [registerModal, { openModal }] = useModal();
const [registerTenUserModal, { openModal: tenUserOpenModal }] = useModal();
const userStore = useUserStore();

// 列表页面公共参数、方法
const { prefixCls, tableContext } = useListPage({
  designScope: 'tenant-template',
  tableProps: {
    title: '租户列表',
    api: getTenantList,
    columns: columns,
    formConfig: {
      schemas: searchFormSchema,
    },
    actionColumn: {
      width: 150,
      fixed: 'right',
    },
    rowSelection: {
      type: "radio"
    },
    beforeFetch: (params) => {
      return Object.assign(params);
    },
  },
});
const [registerTable, { reload }, { rowSelection, selectedRowKeys, selectedRows }] = tableContext;

/**
 * 操作列定义
 * @param record
 */
function getActions(record) {
  return [
    {
      label: '用户',
      onClick: handleSeeUser.bind(null, record.id),
    },
  ];
}

/**
 * 查看用户
 * @param id
 */
async function handleSeeUser(id) {
  tenUserOpenModal(true, {
    id: id,
  });
}

/**
 * 删除成功之后回调事件
 */
function handleSuccess() {
  (selectedRowKeys.value = []) && reload();
}

onMounted(() => {
  //提示信息
  tenantSaasMessage('我的租户')
})
</script>
